package com.adam.framework.jdbc;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import junit.framework.TestCase;

import com.adam.framework.connectionpool.MyDataSource;

public class ConnectionPoolTestCase extends TestCase {
	public void te2stConnect() throws SQLException {
		MyDataSource ds = MyDataSource.getInstance();
		ds.getConnection();

	}

	public void testHandCon() {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();

			String url = "jdbc:mysql://localhost:3306/clm";
			String user = "clm";
			String password = "gangdan";

			Connection conn = DriverManager.getConnection(url, user, password);
			ConnectionHandler conHandler = new ConnectionHandler();
			conHandler.bind(conn);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private class ConnectionHandler implements InvocationHandler {
		Connection con = null;

		public Connection bind(Connection con) {
			this.con = con;
			Connection proxyCon = null;
			try{
				Object o = Proxy.newProxyInstance(
						con.getClass().getClassLoader(), 
						con.getClass().getInterfaces(), this);
				proxyCon = (Connection)o;
					
			}catch(Throwable e){
				e.printStackTrace();
			}
			return proxyCon;
		}

		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
			Object obj = null;
			System.out.print("asdf");
			return obj;
		}
	}
}
